﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

using CrystalDecisions.CrystalReports.Engine;

public partial class Report1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string sql = "select * from com_PingZhengBiao where pingzhenghao=9";
        string DBConfig_sql = @"Data Source=PETER-PC\SQLEXPRESS;Initial Catalog=Company;User ID=sa;Password=123";
        DataSet ds = new DataSet();
        SqlConnection sqlCon = new SqlConnection(DBConfig_sql);
        SqlCommand sqlCmd = new SqlCommand(sql, sqlCon);
        SqlDataAdapter sqlAd = new SqlDataAdapter();
        sqlAd.SelectCommand = sqlCmd;
        sqlAd.Fill(ds, "PingZheng");
        CrystalReportSource1.ReportDocument.Load(Server.MapPath("Report1.rpt"));
        //注意此处必需指明Dataset中的表的名称，否则会提示“您请求的报表需要更多信息.”
        CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables["PingZheng"]);
        //{?}中的参数可以不用赋值，即使赋了值也不起作用。
        //CrystalReportSource1.ReportDocument.ParameterFields["Sum"].CurrentValues.AddValue("500");
        //CrystalReportSource1.ReportDocument.ParameterFields["Title"].CurrentValues.AddValue("这时推模式的报表样例！");
        TextObject tb = (TextObject)CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text12"];
        tb.Text = "500";
        CrystalReportSource1.DataBind();

        CrystalReportViewer1.ReportSource = CrystalReportSource1;
        CrystalReportViewer1.DataBind();
    }
}
